package cn.gyxy;

import cn.gyxy.service.realm.ShiroRealm;
import org.apache.shiro.realm.Realm;
import org.apache.shiro.spring.web.config.DefaultShiroFilterChainDefinition;
import org.apache.shiro.spring.web.config.ShiroFilterChainDefinition;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

import java.util.LinkedHashMap;

@MapperScan("cn.gyxy.mapper")
@SpringBootApplication
public class BsOneApplication {

    public static void main(String[] args) {
        SpringApplication.run(BsOneApplication.class, args);
    }

    @Bean//将ream对象交给spring管理
    public Realm realm() {//org.apache.shiro.realm.Realm
        return new ShiroRealm();
    }

    @Bean
    public ShiroFilterChainDefinition shiroFilterChainDefinition() {
        DefaultShiroFilterChainDefinition chainDefinition
                = new DefaultShiroFilterChainDefinition();
        LinkedHashMap<String, String> map = new LinkedHashMap<>();
        //设置允许匿名访问的资源路径(不需要登录即可访问)
        map.put("/login", "anon");//anon对应shiro中的一个匿名过滤器
        map.put("/login.html", "anon");
        map.put("/loginbs", "anon");
// 设置需认证以后才可以访问的资源(注意这里的顺序,匿名访问资源放在上面)
        map.put("/**", "authc");//authc 对应一个认证过滤器，表示认证以后才可以访问
        chainDefinition.addPathDefinitions(map);
        return chainDefinition;
    }

}
